package com.ideal.manage.esms.service.project;

import com.ideal.manage.esms.bean.project.ParameterInfo;
import com.ideal.manage.esms.bean.sys.User;
import com.ideal.manage.esms.config.shiro.MyShiroRealm;
import com.ideal.manage.esms.repository.framework.MySpecification;
import com.ideal.manage.esms.repository.framework.SpecificationOperator;
import com.ideal.manage.esms.repository.programme.ParameterInfoRepository;
import com.ideal.manage.esms.util.HttpRequests;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;

@Service
@CacheConfig(cacheNames = "projectCache")
public class ProjectService {
    @Resource
    ParameterInfoRepository parameterInfoRepository;
    @Cacheable(value = "projectPage")
    public Page<ParameterInfo> findAllParameterInfos(int pageNum, HttpServletRequest request) {
        List<SpecificationOperator> operators = HttpRequests.getParametersStartingWith(request, "Q_");
        Sort sort = new Sort(Sort.Direction.DESC, "createTime");
        SpecificationOperator operator = new SpecificationOperator("isValid", "1", "EQ");
        SpecificationOperator operator2 = new SpecificationOperator("source", "5", "EQ");
        operators.add(operator);
        operators.add(operator2);
        MySpecification<ParameterInfo> mySpecifications = new MySpecification<>(operators);
        Pageable pageable = new PageRequest(pageNum, 15, sort);
        Page<ParameterInfo> page = parameterInfoRepository.findAll(mySpecifications, pageable);
        return page;
    }

}



   


